﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'table', 'common', 'commonTable', 'optimizeSelectOption'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            commonTable = layui.commonTable,
            common = layui.common;
        //加载数据
        wcLoading.close();
        //权限控制(js是值传递)
        toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
        var moduleId = $.request("moduleId");
        var modulename = $.request("modulename");
        if (!!modulename) {
            try {
                $('#txt_name').val(decodeURI(escape(modulename)));
            } catch (e) {
                $('#txt_name').val(decodeURI(modulename));
            }

        }
        commonTable.rendertable({
            elem: '#currentTableId',
            id: 'currentTableId',
            url: "/SystemManage/ModuleButton/GetTreeGridJson?moduleId=" + moduleId,
            cols: [[
                { field: 'F_FullName', title: '名称', width: 120 },
                {
                    field: 'F_Location', title: '位置', width: 60,
                    templet: function (d) {
                        if (d.F_Location == 1) {
                            return "初始";
                        } else {
                            return "选中";
                        }
                    }
                },
                { field: 'F_JsEvent', title: '事件', width: 80 },
                { field: 'F_UrlAddress', title: '连接', width: 250 },
                //{
                //    field: 'F_Split', title: '分开', width: 60,
                //    templet: function (d) {
                //        if (d.F_IsMenu == true) {
                //            return "<input type='checkbox' checked='' lay-skin='primary' name='true' valuer='true'>";
                //        } else {
                //            return "<input type='checkbox' name='false'  lay-skin='primary' valuer='false'>";
                //        }
                //    }
                //},
                {
                    field: 'F_IsPublic', title: '公共', width: 80,
                    templet: function (d) {
                        if (d.F_IsPublic == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>是</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>否</span>";
                        }
                    }
                }, 
                {
                    field: 'F_EnabledMark', title: '状态', width: 80,
                    templet: function (d) {
                        if (d.F_EnabledMark == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                        }
                    }
                }, 
                { field: 'F_SortCode', title: '排序', width: 60 },
                { field: 'F_Description', title: '备注', minWidth: 100 },
            ]]
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var queryJson = data.field.txt_keyword;
            //执行搜索重载
            commonTable.reloadtable({
                elem: 'currentTableId',
                curr: 1,
                queryJson: queryJson
            });
            module = null;
            return false;
        });
        var module;
        table.on('row(currentTableFilter)', function (obj) {
            obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
            module = obj;
        })
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听操作
                common.modalOpen({
                    title: "添加按钮",
                    url: "/SystemManage/ModuleButton/Form?moduleId=" + moduleId,
                    width: "500px",
                    height: "440px",
                });
            }
            else if (obj.event === 'delete') {
                if (module == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.deleteForm({
                    url: "/SystemManage/ModuleButton/DeleteForm",
                    param: { keyValue: module.data.F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'edit') {
                if (module == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "编辑按钮",
                    url: "/SystemManage/ModuleButton/Form?moduleId=" + moduleId+"&keyValue=" + module.data.F_Id,
                    width: "500px",
                    height: "440px",
                });
            }
            else if (obj.event === 'details') {
                if (module == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "查看按钮",
                    url: "/SystemManage/ModuleButton/Details?keyValue=" + module.data.F_Id,
                    width: "500px",
                    height: "440px",
                    btn: []
                });
            }
            else if (obj.event === 'clonebutton') {
                common.modalOpen({
                    title: "克隆按钮",
                    url: "/SystemManage/ModuleButton/CloneButton?moduleId=" + moduleId,
                    width: "400px",
                    height: "600px",
                });
            }
            else if (obj.event === 'TABLE_SEARCH') {
                var _that = $("#searchField");
                if (_that.hasClass("layui-hide")) {
                    _that.removeClass('layui-hide');
                } else {
                    _that.addClass('layui-hide');
                }
            }
            return false;
        });
    });
</script>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset layui-hide" id="searchField">
            @*<legend>搜索信息</legend>*@
            <div>
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">菜单名称:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_name" name="txt_name" readonly class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" id="toolbar">
                <button id="NF-add" authorize="yes" class="layui-btn layui-btn-sm data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新建</button>
                <button id="NF-edit" authorize="yes" class="layui-btn layui-btn-sm layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                <button id="NF-delete" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                <button id="NF-details" authorize="yes" class="layui-btn layui-btn-sm layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
                <button id="NF-clonebutton" authorize="yes" class="layui-btn layui-btn-sm data-clonebutton-btn layui-hide" lay-event="clonebutton"><i class="fa fa-paste"></i>克隆按钮</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>